<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class Welcome extends CI_Controller {
	var $jumlah=0;
	var $image;
	var $q;
	public function index() {
		//kudu kelipatan 8
		$jumlah = 160;
		$q = 'maisie williams';
		$qa = str_replace(' ', '%20', $q);
		for ($i = 1; $i <= (int)($jumlah / 8); $i++) {
			$url = 'http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=' . $qa . '&imgcolor=black&imgsz=xxlarge&rsz=8&start=' . $i;
			$json = file_get_contents($url);
			$json_res = json_decode($json, TRUE);
			//echo '<pre>';
			//print_r($json_res);
			//echo '</pre>';

			foreach ($json_res['responseData']['results'] as $key => $res) {
				echo '<a href="' . $res['url'] . '">' . $res['url'] . '</a>' . '</br>';
				//$this -> copyimage($res['url']);
				//$image[$jumlah]['url']=$res['url'];
				$jumlah++;
			}
		}
		
		

	}

	function getFilename($file) {
		$filename = substr($file, strrpos($file, '/') + 1, strlen($file) - strrpos($file, '/'));
		return $filename;
	}

	function copyimage($url = '',$num_img=0) {
		copy($url, '/data/'.str_replace(' ', '_', $q).'_'.$num_img.'.jpg');
	}

}
